package com.wocao.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wocao.entity.ResponseResult;
import com.wocao.entity.SysPost;
import com.wocao.entity.ZyOwner;
import com.wocao.entity.ZyVisitor;
import com.wocao.service.ZyOwnerService;
import com.wocao.service.ZyVisitorService;
import com.wocao.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;


@RestController
@RequestMapping("/ZyVisitor")
public class ZyVisitorController {


    @Autowired
    private ZyVisitorService zyVisitorService;


    @Autowired
    private ZyOwnerService zyOwnerService;

    @GetMapping("/findZyVisitor")
    public ResponseResult findZyVisitor(@RequestParam(required = false, defaultValue = "1") Long current,
                                        @RequestParam(required = false, defaultValue = "5") Long size,
                                        @RequestParam(required = false, defaultValue = "") String visitorName,
                                        @RequestParam(required = false, defaultValue = "") String visitorPhoneNumber,
                                        @RequestParam(required = false, defaultValue = "") String visitorDate) {
        try {
            IPage<ZyVisitor> zyVisitorAll = zyVisitorService.getZyVisitorAll(current, size, visitorName, visitorPhoneNumber, visitorDate);
            return ResponseResult.ok(zyVisitorAll);
        } catch (Exception e) {
            return ResponseResult.error(500L, "查询失败");
        }
    }

    /**
     * SysPost导出
     *
     * @param resp
     */
    @GetMapping("/exportZyVisitor")
    public void exportZyVisitor(HttpServletResponse resp) {
        List<ZyVisitor> list = zyVisitorService.list();
        try {
            ExcelUtil.export(resp, ZyVisitor.class, list);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

}
